home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE15 / CPPCLASS / OWLDEL / OWLDEL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-17  |  3.0 KB  |  161 lines

  1. #include <owl\applicat.h>
  2. #include <owl\window.h>
  3. #include <owl\slider.h>
  4. #include "dowlsldr.h"
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <windows.h>
  8. #if !defined(__FLAT__)
  9.   #pragma options -xc  -WD
  10. #endif
  11.  
  12. const  WORD ID_THERMOSTAT = 201;
  13.  
  14. class MessageSink
  15. {
  16.     protected:
  17.         TOWLDelphiControl* surrogate;
  18.  
  19.     public:
  20.     MessageSink()
  21.     {
  22.       surrogate = new TOWLSlider;
  23.     }
  24.     TOWLDelphiControl* GetCOMControl(){return surrogate;};
  25.     void AddOWLClass(TWindow *Window)
  26.     {
  27.           if (surrogate != NULL)
  28.              surrogate->InsertOWLControl(Window);
  29.     };
  30.     void Dispatcher(UINT Msg, WPARAM wp, LPARAM lp )
  31.     {
  32.          if (surrogate != NULL)
  33.               surrogate->DoDispatch(Msg, wp, lp);
  34.     };
  35.  
  36. };
  37.  
  38. class TDHSLider : public THSlider, public MessageSink {
  39.  
  40.   public:
  41.       TDHSLider(TWindow*        parent,
  42.                 int             id,
  43.                 int X, int Y, int W, int H,
  44.                 TResId          thumbResId,
  45.                 TModule*        module = 0):
  46.                   THSlider(parent,id,X,Y,W,H,thumbResId, module),
  47.                   MessageSink()
  48.                   {
  49.                       AddOWLClass(this);
  50.                   };
  51.  
  52.   protected:
  53.         void DoChange()
  54.         {
  55.           if (surrogate != NULL)
  56.              ((TOWLSlider *)surrogate)->DoChange();
  57.         }
  58.      virtual void SetPosition(int thumbPos)
  59.      {
  60.          THSlider::SetPosition(thumbPos);
  61.          DoChange();
  62.      }
  63.  
  64.      virtual LRESULT  Dispatch(TEventInfo& info, WPARAM wp, LPARAM lp = 0)
  65.     {
  66.         Dispatcher(info.Msg,wp,lp);
  67.         return TEventHandler::Dispatch(info,wp,lp);
  68.     };
  69. };
  70.  
  71.  
  72. class Tracker
  73. {
  74.   TWindow *CondemnedWindows;
  75.     void AddToCondemnedList(TWindow* win)
  76.      {
  77.         win->SetNext(CondemnedWindows);
  78.         CondemnedWindows = win;
  79.      }
  80.  
  81.   public :
  82.      Tracker(){CondemnedWindows = NULL;};
  83.      ~Tracker()
  84.      {
  85.          //Delete all parent aliases and release all thunks
  86.          while (CondemnedWindows)
  87.           {
  88.              TWindow* next = CondemnedWindows->Next();
  89.              delete CondemnedWindows;
  90.              CondemnedWindows = next;
  91.          }
  92.      }
  93.  
  94.     TWindow *AddParentAlias(HWND far parentHWnd)
  95.     {
  96.         TWindow *aNewParent = GetWindowPtr(parentHWnd);
  97.          //Check if we have a already created to use parent
  98.          if (aNewParent == NULL)
  99.          {
  100.             aNewParent = new TWindow(parentHWnd,::Module);
  101.             AddToCondemnedList(aNewParent);
  102.          }
  103.         return aNewParent;
  104.      }
  105. };
  106.  
  107.  
  108.  
  109.  
  110. //>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<
  111. static Tracker *TrackSliders;
  112.  
  113. extern "C" {
  114.  TOWLDelphiControl *  _export _cdecl
  115.   COMCLASSCONSTRUCTOR(HWND far parentHWnd)
  116.   {
  117.       TDHSLider *OwlControl = NULL;
  118.       TWindow *aParent =
  119.              TrackSliders->AddParentAlias(parentHWnd);
  120.  
  121.       if (aParent != NULL)
  122.       {
  123.          TDHSLider *OwlControl =
  124.              new TDHSLider(
  125.                         aParent,
  126.                         ID_THERMOSTAT,
  127.                         0, 0, 240, 40,
  128.                         IDB_HSLIDERTHUMB ,
  129.                         ::Module);
  130.  
  131.          if (OwlControl != NULL)
  132.             return OwlControl->GetCOMControl();
  133.       }
  134.       return NULL;
  135.   }
  136.  
  137. void  _export _cdecl COMCLASSDESTRUCTOR( TOWLDelphiControl *aControl)
  138. {
  139.   if (aControl != NULL)
  140.      delete aControl;
  141. }
  142.  
  143. }
  144.  
  145. int
  146. OwlMain(int /*argc*/, char* /*argv*/ [])
  147. {
  148.   TrackSliders = new Tracker;
  149.   return 0;
  150. }
  151.  
  152. #pragma argsused
  153.  
  154. int FAR PASCAL WEP (int bSystemExit)
  155. {
  156.   delete TrackSliders;
  157.   return 1;
  158. }
  159.  
  160.  
  161.